import sys, os

from plugins.core.plugin import Plugin
from plugins.core.pluginvideo import PluginVideo
from plugins.core.pluginplaylist import PluginPlaylist

sys.path.append("..")
from src.vobjects.item import Item

from src.config import Config
from src.history import History

class Downloads(Plugin):

    def __init__(self, history: History=History()):
        self.name = "Downloads"
        self.is_query_required = False
        self.query_description = """"""
        self.history = history

        self.flag = "-d"
        self.full_flag = "--downloads"
        self.flag_help = "show rosen downloads list"
        self.flag_action = "store_true"
        
        self.config = Config()
        self.extensions = ('.mp3', '.mp4', '.mkv', '.webm', '.m3u')

    def get_downloads(self):
        items = []
        path = self.config.VideoDownloadDirectory.replace('~', os.path.expanduser('~'))
        for filename in os.listdir(path):
            if filename.endswith(self.extensions):
                video = PluginVideo(playlist_title=filename,
                                    url=path+"/"+filename)
                items.append(video.to_item())

        return items

    def get_items_by_query(self, query: str=""):
        return list()

    def get_items(self):
        return self.get_downloads()


